package com.ruoyi.common.baidu;

import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang3.StringUtils;

/**
 * 	真人认证 结果解析
 * @author liuz
 *
 */
public class AuthUtil {



	/**
	 * 	获取生日
	 * @param appUserAuth
	 * @return
	 */
	public static Date getBirthday(AppUserAuth appUserAuth) {
		Date birthday = new Date();
		try {
			SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
			if(appUserAuth == null) {
				birthday = format.parse("19970520");
			}
			if(StringUtils.isNotEmpty(appUserAuth.getBirthday())) {
				birthday = format.parse(appUserAuth.getBirthday());
			}else {
				if(StringUtils.isNotEmpty(appUserAuth.getIdCard())) {
					birthday = format.parse(appUserAuth.getIdCard().substring(6,14));
				}else {
					birthday = format.parse("19970520");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return birthday;
	}

	/**
	 * 	获取性别
	 * @param appUserAuth
	 * @return
	 */
	public static String getSex(AppUserAuth appUserAuth) {
		String sex = "";
		try {
			if(null != appUserAuth) {
				if(StringUtils.isNotEmpty(appUserAuth.getIdCard())) {
					if (Integer.parseInt(appUserAuth.getIdCard().substring(16).substring(0, 1)) % 2 == 0) {
						sex = "F";
					}else {
						sex = "M";
					}
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return sex;
	}
	public static void main(String[] args) {
		if (Integer.parseInt("430624200001153327".substring(16).substring(0, 1)) % 2 == 0) {
			System.out.println("女");
		}else {
			System.out.println("男");
		}
	}
}
